// 云对象教程: https://uniapp.dcloud.net.cn/uniCloud/cloud-obj
// jsdoc语法提示教程：https://ask.dcloud.net.cn/docs/#//ask.dcloud.net.cn/article/129
module.exports = {
	_before: function() { // 通用预处理器

	},
	// 商品相关函数  ny-goods-picture
	// 添加商品
	async addgoodsPicture(event) {
		const db = uniCloud.database();
		const collection = db.collection("ny-goods-picture");
		const res = await collection.add(event) //event为客户端上传的参数
		return {
			code: 200,
			msg: '添加成功!!',
			data: res
		}
	},
	// 获取商品数据
	async getgoodsPicture(item) {
		const db = uniCloud.database();
		const collection = db.collection("ny-goods-picture");
		let res
		if (item != '') {
			res = await collection.where({
				'author_id': item
			}).get()
		} else {
			res = await collection.get()
		}
		return {
			code: 200,
			msg: '查询成功',
			data: res
		}
	},
	// 修改商品数据
	async updategoodsPicture(_id, item) {
		const db = uniCloud.database();
		const collection = db.collection("ny-goods-picture");
		let res = await collection.doc(_id).update(item)
		return {
			code: 200,
			msg: '修改成功!!',
			data: res
		}
	},
	// 商品销量
	async goodsPictureVolume(_id) {
		const db = uniCloud.database();
		const collection = db.collection("ny-goods-picture");
		let res = await collection.where({
			'_id': _id
		}).get()
		let volume = res.data[0].volume-0+1
		let rea = await collection.doc(_id).update({"volume":volume})
		return {
			code: 200,
			msg: '修改成功!!',
			data: rea
		}
	},
	//查找商品
	async lookgoosPicture(item){
		const db = uniCloud.database();
		const collection = db.collection("ny-goods-picture");
		let res = await collection.where(item).orderBy('create_date','desc').get()
		return {
			code: 200,
			msg: '查找成功!!',
			data: res.data
		}
	}
}